<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <!-- 开发环境版本，包含了有帮助的命令行警告 -->
  <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
</head>

<body>
  <div class="root">
    <h1>留言板</h1>
    <p>{{alert}}</p>
    <input type="text" v-model="text" placeholder="请输入消息"><button @click="add">添加</button>
    <hr>
    <ul v-for="(k,i) in message">
      <li>{{i+1}}---{{k}} <a href="#" @click="remove(i)">删除</a> </li>
    </ul>
  </div>
  <script>
    //创建vue实例
    new Vue({
      el: '.root', //指定当前vue 为哪个容器使用
      data: {
        text: '',
        message: [],
        flag: false,
        alert: ''
      },
      methods: {
        add() {
          // 向数组中添加消息
          if (this.text.length === 0) {
            this.alert = '消息不能为空!'
          } else {
            this.message.push(this.text)
            this.text = ''
          }

        },
        remove(i) {
          this.message.splice(i, 2)
        }

      },
    });
// 不能实现hover出现 删除链接
  </script>
  <style>
    ul li {
      width: 300px;
      height: 25px;
      background-color: #ccc;
    }

    a {
      display: none;
    }

    ul li:hover a {
      display: block;
      float: right;
      padding-right: 20px;
    }
  </style>
</body>

</html>